﻿' •————————————————————————————————————————————————————————————————————————————————————————————————————————————•
' |                                                                                                            |
' |    GeoLock is a proof of concept (PoC). GeoLock uses Geosense for Windows,                                 |
' |    Microsoft Windows 7 Sensor and Location Interop Sample Library, Microsoft WindowsAPICodePack            |
' |    and Microsoft Bing Maps SDK to demonstrate how to retrieve geolocation data without                     |
' |    Global Positioning System (GPS) hardware.                                                               |
' |                                                                                                            |
' |    The GeoLocK application was written in VB.NET (WPF). The COM Interop Windows7.SensorAndLocation.dll,    |
' |    Microsoft.WindowsAPICodePack.dll and Microsoft.Maps.MapControl.WPF.dll supplied                         |
' |    with this application are x86 binaries.                                                                 |
' |                                                                                                            |
' |    Copyright (C) 2012 Pascal Hubert aka Néo <http://geolock.codeplex.com/>                                 |
' |                                                                                                            |
' |    Project administrator : Pascal Hubert aka Néo (neojudgment@hotmail.com)                                 |
' |                                                                                                            |
' |    This program is under Microsoft Public License (Ms-PL)                                                  |
' |                                                                                                            |
' |    You should have received a copy of the Microsoft Public License (Ms-PL)                                 |
' |    along with this program.  If not, see <http://msdn.microsoft.com/en-us/library/ff647936.aspx>.          |
' |                                                                                                            |
' •————————————————————————————————————————————————————————————————————————————————————————————————————————————•
Public Class Message
    Public Shared MustScan As Boolean

    Public Sub New()

        InitializeComponent()

        If Settings.Update Then
            If Settings.GeolockUpdate Then
                LabelMessage1.Content = "a new version of GeoLock is available"
                LabelMessage2.Content = "Do you want to download this version?"
                ButtonCancel.Visibility = Visibility.Visible
            Else
                LabelMessage1.Content = "no update avaible"
                LabelMessage2.Content = "You have the latest version of GeoLock."
                ButtonCancel.Visibility = Visibility.Hidden
            End If
        Else
            If MainWindow.SensorNotPresent Then
                LabelMessage1.Content = "Geosense sensor is not present"
                LabelMessage2.Content = "Do you want to download the sensor?"
                ButtonCancel.Visibility = Visibility.Visible
            End If
            If Settings.SaveChange Then
                LabelMessage1.Content = "GeoLock options saved"
                LabelMessage2.Content = "Please restart GeoLock for these options to take effect."
                ButtonCancel.Visibility = Visibility.Hidden
            End If
            If Settings.ComPortScan Then
                LabelMessage1.Content = "ComPort Scan"
                LabelMessage2.Content = "This will attempt to discover your GPS Hardware."
                ButtonCancel.Visibility = Visibility.Visible
            End If
            If Settings.ComPortDiscovered = 1 Then
                LabelMessage1.Content = "ComPort Scan"
                LabelMessage2.Content = "GPS Hardware successfully discovered on COM" & My.Settings.ComPort & "."
                ButtonCancel.Visibility = Visibility.Hidden
            ElseIf Settings.ComPortDiscovered = 2 Then
                LabelMessage1.Content = "ComPort Scan"
                LabelMessage2.Content = "GPS Hardware not found!"
                ButtonCancel.Visibility = Visibility.Hidden
            End If
            If MustScan Then
                LabelMessage1.Content = "ComPort Scan"
                LabelMessage2.Content = "Scan in progress. Please wait!"
                ButtonCancel.Visibility = Visibility.Hidden
                ButtonOK.Visibility = Visibility.Hidden
            End If
        End If
    End Sub

    Private Sub ButtonOkClick(sender As System.Object, e As RoutedEventArgs) Handles ButtonOK.Click

        If Settings.GeolockUpdate Then
            Process.Start("http://zguidetv.codeplex.com/")
        End If

        If MainWindow.SensorNotPresent Then
            Process.Start("http://www.geosenseforwindows.com/")
        End If

        If Settings.ComPortScan Then
            MustScan = True
        End If

        Settings.ComPortScan = False
        Settings.Update = False
        MainWindow.SensorNotPresent = False
        Close()
    End Sub

    Private Sub ButtonCancelClick(sender As System.Object, e As RoutedEventArgs) Handles ButtonCancel.Click

        Settings.ComPortScan = False
        Settings.Update = False
        MainWindow.SensorNotPresent = False
        Close()
    End Sub
End Class
